package com.netty.demo.heartbeat;

import java.util.concurrent.TimeUnit;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class HeartbeatClientHandler extends SimpleChannelInboundHandler<ByteBuf>{

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
		ctx.writeAndFlush(msg);
		
	}
	
	@Override
	public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        super.channelInactive(ctx);
        //重新連接服務器
        ctx.channel().eventLoop().schedule(new Runnable() {
            public void run() {
                new HeartbeatClient("127.0.0.1",8007).doConnect();
            }
        }, 2, TimeUnit.SECONDS);
        ctx.close();
    }
}
